﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Microsoft.Samples.Kinect.SkeletonBasics
{
    class GestureRegressionModel
    {

        private int length;
        private List<Tuple<float, float, float, float>> info;
        private List<List<float>> covariances;
        //times, x, y, stddev

        public GestureRegressionModel() {
            info = new List<Tuple<float, float, float, float>>();
            covariances = new List<List<float>>();
        }

        public void readData(String modelFile, String covarianceFile) {

            StreamReader reader = new StreamReader(modelFile);
            Console.WriteLine("reading model file");
            int x = 0;

            while (!reader.EndOfStream)
            {
                String strLine = reader.ReadLine();
                String[] values = strLine.Split(Convert.ToChar(","));
                if(values[0].Equals("")){
                    break;
                }
                else{
                    Tuple<float, float, float, float> tup = new Tuple<float, float, float, float>
                        (float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]), 0);
                    info.Add(tup);
                    x++;
                }
            }
            length = x;
            Console.Out.WriteLine("Total model length is " + length);


            reader = new StreamReader(covarianceFile);
            Console.WriteLine("reading covariance file");

            while (!reader.EndOfStream)
            {
                string strLine = reader.ReadLine();
                List<float> cov = new List<float>();

                String[] values = strLine.Split(Convert.ToChar(","));
                if (values[0].Equals(""))
                {
                    break;
                }
                else
                {
                    foreach (String str in values)
                    {

                        cov.Add(float.Parse(str));
                    }
                }
                covariances.Add(cov);
            }


            reader.Close();

            //foreach (Tuple<double, double, double, double> tup in info) {
            //    Console.WriteLine(tup);
            //}
        }

        public int getLength() {
            return length;
        }

        public List<Tuple<float, float, float, float>> getGMRModelValues() {
            return info;
        }

        
        public List<List<float>> getCovariances() {
            return covariances;
        }

    }
}
